package com.example.paimengshop.mypanes;

import com.example.paimengshop.dataclass.Commodity;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;

public class CartPane extends HBox {

    private CheckBox checkBox;

    private HBox hBox;

    private Commodity commodity;

    private ImageView imageView;

    private Label nameLabel;

    private Label price;

    public CheckBox getCheckBox()
    {
        return checkBox;
    }

    private boolean selected;//多选框是否被选中

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }

    public void selectHide() {
        this.checkBox.setVisible(false);
    }

    public Commodity getCommodity() {
        return commodity;
    }

    public CartPane(Commodity commodity) {
        this.hBox = new HBox();
        this.commodity = commodity;
        this.checkBox = new CheckBox();
        this.imageView=new ImageView(new Image(commodity.getImageURL()));
        this.nameLabel=new Label(commodity.getName());
        this.price=new Label(commodity.getPrice()+"元");

        super.setPrefSize(1000, 200);
        super.setAlignment(Pos.CENTER_LEFT);
        super.setPadding(new Insets(0, 0, 0,
                100));

        hBox.setPrefSize(1000, 200);
        hBox.setSpacing(20);
        hBox.setAlignment(Pos.CENTER);

        checkBox.setPrefSize(100, 200);
        imageView.setFitWidth(160);
        imageView.setFitHeight(160);

        nameLabel.setPrefSize(300, 160);
        nameLabel.setWrapText(true);
        nameLabel.setAlignment(Pos.CENTER_LEFT);
        nameLabel.setFont(new Font(20));

        price.setPrefSize(300, 160);
        price.setAlignment(Pos.CENTER_RIGHT);
        price.setFont(new Font(20));
        price.setStyle("-fx-font-weight:bold");

        hBox.getChildren().addAll(checkBox, imageView, nameLabel, price);

        super.getChildren().add(hBox);
    }
}
